{extend name="public:layout" /}
{block name="title"}订单管理{/block}
{block name="head"}
{:widget('common/Form/dateRes')}
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 订单列表</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <form class="form-inline" method="post">
                    <div class="form-group">
                        <label>时间段</label>
                        <input type="text" class="form-control laydate-icon layer-date" style="width:150px;" name="bdate" onclick="laydate();" value="{$query.bdate}" />
                        <input type="text" class="form-control laydate-icon layer-date" style="width:150px;" name="edate" onclick="laydate();" value="{$query.edate}" />
                    </div>
                    <div class="form-group">
                        <select class="form-control" name="order_from">
                            <option value="">订单来源</option>
                            <option value="1" {eq name="query.order_form" value="1"}selected{/eq}>pc端</option>
                            <option value="2" {eq name="query.order_form" value="2"}selected{/eq}>手机端</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" name="searchkey">
                            <option value="order_sn" {eq name="query.searchkey" value="order_sn"}selected{/eq}>订单编号</option>
                            <option value="buyer_username" {eq name="query.searchkey" value="buyer_username"}selected{/eq}>下单人</option>
                            <option value="consignee" {eq name="query.searchkey" value="consignee"}selected{/eq}>收货人</option>
                            <option value="address" {eq name="query.searchkey" value="address"}selected{/eq}>收货地址</option>
                            <option value="tel_phone" {eq name="query.searchkey" value="tel_phone"}selected{/eq}>联系电话</option>
                        </select>
                        <select class="form-control" name="searchquery">
                            <option value="eq" {eq name="query.searchquery" value="eq"}selected{/eq}>精确匹配</option>
                            <option value="like" {eq name="query.searchquery" value="like"}selected{/eq}>模糊匹配</option>
                        </select>
                        <div class="input-group">
                            <input class="form-control" type="text" name="searchvalue" value="{$query.searchvalue}"/>
                        </div>
                    </div>
                    <button type="submit" class="btn btn-info">
                        <i class="fa fa-search"></i> 搜索
                    </button>
                    <a class="btn btn-white" href="{:url('index',['mid'=>$Request.param.mid])}">
                        <i class="fa fa-trash"></i> 清空
                    </a>
                </form>
            </div>
            <ul class="nav nav-tabs" id="tab_search">
                <li {eq name="query.order_genre" value="0"}class="active"{/eq}><a href="{:url('index',['order_genre'=>0])}">所有订单</a></li>
                <li {eq name="query.order_genre" value="1"}class="active"{/eq}><a href="{:url('index',['order_genre'=>1])}">未付款订单</a></li>
                <li {eq name="query.order_genre" value="2"}class="active"{/eq}><a href="{:url('index',['order_genre'=>2])}">已付款未发货</a></li>
                <li {eq name="query.order_genre" value="3"}class="active"{/eq}><a href="{:url('index',['order_genre'=>3])}">已付款已发货</a></li>
                <li {eq name="query.order_genre" value="4"}class="active"{/eq}><a href="{:url('index',['order_genre'=>4])}">已完成</a></li>
                <li {eq name="query.order_genre" value="5"}class="active"{/eq}><a href="{:url('index',['order_genre'=>5])}">积分</a></li>
                <li {eq name="query.order_genre" value="6"}class="active"{/eq}><a href="{:url('index',['order_genre'=>6])}">集采</a></li>
                <li {eq name="query.order_genre" value="7"}class="active"{/eq}><a href="{:url('index',['order_genre'=>7])}">竞拍</a></li>
                <li {eq name="query.order_genre" value="8"}class="active"{/eq}><a href="{:url('index',['order_genre'=>8])}">退款</a></li>
                <li {eq name="query.order_genre" value="9"}class="active"{/eq}><a href="{:url('index',['order_genre'=>9])}">作废</a></li>
            </ul>
            <table class="table table-condensed table-hover" id="grid">
                <thead>
                <tr>
                    <th width="50">#</th>
                    <th>订单</th>
                    <th>收货信息</th>
                    <th>时间</th>
                    <th>订单金额</th>
                    <th>应付款</th>
                    <th>积分</th>
                    <th>订单状态</th>
                    <th width="80">操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="list" id="vo"}
                <tr>
                    <td>
                        <input name="order_id[]" type="checkbox" class="checkbox" value="{$vo.order_id}" />
                    </td>
                    <td>
                        下单人:{$vo['buyer_username']}<br/>
                        编号:{$vo.order_sn}<br/>
                        客户端来源:{$vo['order_from']==2?'手机端':'PC端'}<br/>
                    </td>
                    <td>
                        收货人:{$vo.consignee}<br/>
                        电话:{$vo.tel_phone}
                    </td>
                    <td>
                        下单时间:{$vo.create_time|date='Y-m-d H:i',###}<br/>
                        {neq name="vo.payment_time" value="0"}
                        付款时间:{$vo.payment_time|date='Y-m-d H:i',###}<br/>
                        {/neq}
                        {neq name="vo.shipping_time" value="0"}
                        发货时间:{$vo.shipping_time|date='Y-m-d H:i',###}<br/>
                        {/neq}
                        {neq name="vo.finnshed_time" value="0"}
                        完成时间:{$vo.finnshed_time|date='Y-m-d H:i',###}<br/>
                        {/neq}
                        {neq name="vo.refund_time" value="0"}
                        退款时间:{$vo.refund_time|date='Y-m-d H:i',###}<br/>
                        {/neq}
                    </td>
                    <td>
                        商品总价:{$vo.goods_amount}元<br/>
                        {gt name="vo.shipping_fee" value="0"}
                        +配送费:{$vo.shipping_fee|default=0}元<br/>
                        {/gt}
                        {gt name="vo.card_price" value="0"}
                        -代金券:{$vo.card_price|default=0}元<br/>
                        {/gt}
                        {gt name="vo.promotion_amount" value="0"}
                        -优惠金额:{$vo.promotion_amount|default=0}元<br/>
                        {/gt}
                        <span class="text-danger">=订单金额:{$vo.order_price}元</span><br/>
                    </td>
                    <td>
                        应付款：{$vo.order_price}元<br/>
                        {gt name="vo.refund_amount" value="0"}
                        -退款:{$vo.refund_amount}元<br/>
                        {/gt}
                        <span class="text-danger">实付款：{$vo['pay_price']-$vo['refund_amount']}元</span><br/>
                    </td>
                    <td>
                        赠送积分：{$vo.order_give_point|default=0}<br/>
                        消费积分：{$vo.order_pay_point|default=0}<br/>
                    </td>
                    <td>
                        {$vo.order_status_text}<br/>
                        {$vo.pay_status_text}<br/>
                        {$vo.shipping_status_text}<br/>

                    </td>
                    <td>
                        <style>
                            .margin-bottom-xs{margin-bottom:5px;}
                        </style>
                        {if condition="($vo['order_status'] == 1) && ($vo['shipping_status']==0) "}
                            <a href="javascript:;" class="btn btn-success btn-xs margin-bottom-xs" onclick="delivery(this);" data-url="{:url('orderDelivery',['order_id'=>$vo['order_id']])}">快速发货</a><br/>
                        {/if}
                        <a href="javascript:;" class="btn btn-white btn-xs margin-bottom-xs" onclick="showDetail(this)" data-url="{:url('ShopOrder/orderDetail',['order_sn'=>$vo['order_sn']])}">查看订单</a><br/>
                        <a class="btn btn-primary btn-xs margin-bottom-xs" href="{:url('orderPrint',['order_sn'=>$vo['order_sn']])}" target="_blank">打印订单</a><br/>
                        <a class="btn btn-success btn-xs margin-bottom-xs" href="{:url('orderHander',['order_sn'=>$vo['order_sn']])}">处理订单</a><br/>
                        {if condition="($vo['order_status'] == 0) && ($vo['shipping_status']==0) && ($vo['pay_status']==0) "}
                        <a href="javascript:;" class="btn btn-warning btn-xs" onclick="doAction(this);"
                           data-msg="只有未付款并未确认得订单可删除<br/>确认删除吗？" data-url="{:url('orderDel')}" data-params="order_id={$vo.order_id}">删除订单</a>
                        {/if}
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
            <div class="p8">
                <div class="pull-left">
                    <div class="form-inline">
                        <button type="button" onclick="CheckAll();" class="btn btn-white">全</button>
                        <button type="button" onclick="CheckOther();" class="btn btn-white">反</button>
                        <button type="button" onclick="batchDel(CheckboxValue())" class="btn btn-danger">
                            <i class="fa fa-trash"></i> 批量删除
                        </button>
                        <button type="button" onclick="batchConfirm(CheckboxValue());" class="btn btn-success">
                            <i class="fa fa-check"></i> 批量确认
                        </button>
                    </div>
                </div>
                <div class="page-bar">{$list->render()}</div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    //显示订单详情
    function showDetail(obj) {
        var url = $(obj).data('url');
        openDialog('订单详情', url, '800px', '520px');
    }
    //批量删除订单
    function batchDel(orderId) {
        if (IsMore(orderId)) {
            var url = "{:url('orderDel')}";
            var params = {'order_id': orderId};
            doConfirm('只有未付款并未确认得订单可删除<br/>确认删除吗？', url, params, function (data) {
                if (data.code == 1) {
                    top.layer.msg(data.msg, {icon: 1, time: 800}, function () {
                        rePage();
                    });
                }
            });
        }
    }
    //批量删除订单
    function batchConfirm(orderId) {
        if (IsMore(orderId)) {
            var url = "{:url('orderConfirm')}";
            var params = {'order_id': orderId};
            doConfirm('只有未确认得订单可操作<br/>确认操作吗？', url, params, function (data) {
                if (data.code == 1) {
                    top.layer.msg(data.msg, {icon: 1, time: 800}, function () {
                        rePage();
                    });
                }else{
                    layer.alert(data.msg);
                }
            });
        }
    }
    //快速发货
    function delivery(obj) {
        var url = $(obj).data('url');
        layer.open({
            title: '订单发货',
            type: 2,
            area: ['800px', '480px'],
            content: url
        });
    }
</script>
{/block}